<?php /*a:2:{s:65:"/www/wwwroot/cloud_boss/application/admin/view/company/index.html";i:1604050254;s:64:"/www/wwwroot/cloud_boss/application/admin/view/public/basic.html";i:1573743224;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo htmlentities((isset($title) && ($title !== '')?$title:'重庆优合一众')); ?></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugs/layui/css/layui.css" media="all"/>
    <!--<link rel="stylesheet" href="/static/layuicms/css/index.css" media="all" />-->
    
<link rel="stylesheet" href="/static/css/admin/public.css" media="all"/>

</head>
<body class="<?php echo htmlentities((isset($body) && ($body !== '')?$body:'childrenBody')); ?>">

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <input type="hidden" class="layui-input app_sn" value="<?php echo htmlentities($app_sn); ?>"/>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input company_name" placeholder="请输入企业名称"/>
                </div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input contacts" placeholder="请输入联系人"/>
                </div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input contacts_tel" placeholder="请输入联系人电话"/>
                </div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input business_license_pic" placeholder="请输入营业执照编号"/>
                </div>

                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>

            <?php if(auth("$thisClass/add")): ?>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addNews_btn">新增企业</a>
            </div>
            <?php endif; ?>


        </form>
    </blockquote>
   <table id="userList" lay-filter="userList"></table>

    <script type="text/html" id="checkStatus">
        <input type="checkbox" name="{{d.company_id}}" value="{{d.status}}" lay-skin="switch" lay-text="启用|冻结" lay-filter="modifyStatus" {{ d.status== 1 ? 'checked' : '' }}>
        </script>

        <!--操作-->
        <script type="text/html" id="userListBar">

            <!--<?php if(auth("$thisClass/edit_password")): ?>-->
            <!--<a class="layui-btn layui-btn-sm layui-btn-green" lay-event="edit_password">修改密码</a>-->
            <!--<?php endif; ?>-->

            <?php if(auth("$thisClass/edit")): ?>
            <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
            <?php endif; ?>

            <!--        <?php if(auth("$thisClass/del")): ?>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
                    <?php endif; ?>-->

            <a class="layui-btn layui-btn-sm layui-btn-warm" onclick="getSetting('{{d.company_id}}')">设置服务费</a>
        </script>
    </form>
    
<script type="text/javascript" src="/static/plugs/jquery/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="/static/plugs/layui/layui.js"></script>
<script type="text/javascript" src="/static/admin.js"></script>
<script type="text/javascript" src="/static/js/admin/api.js"></script>

    <script>
        layui.use(['laydate', 'form', 'layer', 'table', 'laytpl'], function () {
            var form = layui.form,
                    layer = parent.layer === undefined ? layui.layer : top.layer,
                    $ = layui.jquery,
                    laytpl = layui.laytpl,
                    table = layui.table,
                    laydate = layui.laydate;

            //日期范围
            laydate.render({
                elem: '#create_at'
                , range: true
            });
            var app_sn = $(".app_sn").val();
            //用户列表
            var tableIns = table.render({
                elem: '#userList',
                url: '/Api/Company/getLists',
                method: 'POST',
                contentType: 'application/json; charset=UTF-8',
                headers:{
                    "token":'bbbbb'
                },
                where:{"app_sn":app_sn},
                cellMinWidth: 95,
                page: true,
                height: "full-125",
                limits: [10, 15, 20, 25],
                limit: 20,
                id: "userListTable",
                request: {
                    limitName: 'pageSize', //每页数据量的参数名，默认：limit
                },
                cols: [[
                        {type: "checkbox", fixed: "left", minWidth: 50},
                        {field: 'company_id', title: 'ID', minWidth: 50, align: "center"},
                        {field: 'company_no', title: '编号', minWidth: 100, align: "center"},
                        {field: 'company_name', title: '企业名称',  minWidth: 200,align: 'center'},
                        {field: 'current_money', title: '当前余额/元', minWidth: 150, align: 'center'},
                        {field: 'cumulative_money', title: '累计余额/元',  minWidth:150,align: 'center'},
                        {field: 'company_addr', title: '企业地址',  minWidth: 250,align: 'center'},
                        {field: 'status', title: '启用状态', minWidth: 100, templet: '#checkStatus', unresize: true, align: "center"},
                        {field: 'create_time', title: '入驻时间',minWidth: 210, align: 'center'},
                        {field: 'company_seal', title: '公章', minWidth: 150, align: 'center',templet:'<div><img src="{{d.company_seal}}"  onclick=preview("{{d.company_seal}}")></div>'},
                        {title: '操作', minWidth: 175, templet: '#userListBar', fixed: "right", align: "center"}

                    ]]
            });

            //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
            $(".search_btn").on("click", function () {

                if ($(".searchVal").val() != '') {
                    //执行重载
                    table.reload('userListTable', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            //传参数
                                company_name: $(".company_name").val(),
                                contacts: $(".contacts").val(),
                                contacts_tel: $(".contacts_tel").val(),
                                business_license_pic: $(".business_license_pic").val(),
                               app_sn: $(".app_sn").val(),

                        },
                       
                    });
                     table.render();
                   // layer.msg('查询成功');
                } else {
                    layer.msg("请输入搜索的内容");
                }
            });

        // 添加
        function addUser(edit) {
            var index = layui.layer.open({
                title: "新增企业",
                type: 2,
                content: '<?php echo url("$thisClass/add"); ?>',
                success: function (layero, index) {
                   
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(index);
            })
        }

        // 编辑
        function editUser(edit) {
            var index = layui.layer.open({
                title: "编辑企业",
                type: 2,
                content: '<?php echo url("$thisClass/edit"); ?>?company_id=' + edit.company_id,
                success: function (layero, index) {
                    var body = layui.layer.getChildFrame('body', index);
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(index);
            })
        }

            //修改密码
            function edit_passwordUser(edit) {
                var index = layui.layer.open({
                    title: "修改密码",
                    type: 2,
                    area: ['800px', '500px'],
                    content: '<?php echo url("$thisClass/edit_password"); ?>?id=' + edit.id,
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        setTimeout(function () {
                            layui.layer.tips('点击此处返回角色列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        }, 500)
                    }
                })
                // layui.layer.full(index);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                $(window).on("resize", function () {
                    layui.layer.full(index);
                })
            }


            $(".addNews_btn").click(function () {
                addUser();
            })



            //监听状态操作
            form.on('switch(modifyStatus)', function (obj) {
                $.ajax({
                    method: "POST",
                    url: '/Api/Company/changeStatus',
                    contentType: 'application/json; charset=UTF-8',
                    header: {
                        'token': "bbbb", // 默认值
                    },
                    dataType:'json',
                    data: JSON.stringify({company_id:this.name}),
                    success: (data) => {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1});
                        } else {
                            layer.msg(data.msg, {icon: 2}, function () {
                                tableIns.reload();
                                layer.close();
                            });
                        }
                    },
                    error: () => {
                        layer.msg('系统错误，请稍后再试', {icon: 2}, function () {
                            tableIns.reload();
                        });
                    }
                })
            });
               
            //列表操作
            table.on('tool(userList)', function (obj) {
                var layEvent = obj.event,
                        data = obj.data;

                if (layEvent === 'edit') { //编辑
                    editUser(data);
                } else if (layEvent === 'edit_password') {
                    edit_passwordUser(data);
                } else if (layEvent === 'usable') { //启用禁用
                    var _this = $(this),
                            usableText = "是否确定禁用此用户？",
                            btnText = "已禁用";
                    if (_this.text() == "已禁用") {
                        usableText = "是否确定启用此用户？",
                                btnText = "已启用";
                        console.log('3333333333');
                        console.log(data);
                    }
                    layer.confirm(usableText, {
                        icon: 3,
                        title: '系统提示',
                        cancel: function (index) {
                            console.log('1111111111');
                            layer.close(index);
                        }
                    }, function (index) {
                        _this.text(btnText);
                        layer.close(index);
                    }, function (index) {
                        layer.close(index);
                    });
                } else if (layEvent === 'del') { //删除
                    layer.confirm('确定删除此用户？', {icon: 3, title: '提示信息'}, function (index) {
                        $.get('<?php echo url("$thisClass/del"); ?>', {
                            id: data.id  //将需要删除的newsId作为参数传入
                        }, function (data) {
                            console.log(data);
                            if (data.code == 0) {
                                layer.msg(data.msg, {icon: 1}, function () {
                                    tableIns.reload();
                                    layer.close(index);
                                });
                            } else {
                                layer.msg(data.msg, {icon: 2});
                            }
                        })
                    });
                }
            });

        })
        //预览
        function preview(src){
            layer.photos({ photos: {"data": [{"src": src}]} });
        }
        function getSetting(company_id){
            var app_sn = $(".app_sn").val();
            window.location.href='<?php echo url("equipments/index"); ?>?company_id='+company_id+"&app_sn="+app_sn;
        }
    </script>
    
</body>
</html>